import logging

import pytest

from resource.pom.settings import Settings


class Test:
    app = Settings

    @pytest.mark.parametrize('setup_teardown', [app.bundle_name], indirect=True)
    def test(self, setup_teardown, device):
        logging.info('步骤1.点击设置应用')
        device.start_ability(self.app.bundle_name, self.app.ability_name)
        logging.info('预期结果1.进入设置界面')
        device.assert_current_window(self.app.window_name)

        logging.info('步骤2.点击隐私')
        device.click(*self.app.privacy_item)
        logging.info('预期结果2.进入隐私')
        device.refresh_layout()
        device.assert_text_exist('证书与凭据')

        logging.info('步骤3.点击证书与凭证')
        device.click_element(device.get_element_by_text('证书与凭据'))
        logging.info('预期结果3.进入证书与凭证')
        device.refresh_layout()
        device.assert_text_exist('CA证书')
        device.assert_text_exist('凭据列表')
        device.assert_text_exist('从存储设备安装')
        device.assert_text_exist('删除所有证书与凭据')

        logging.info('步骤4.点击受信任的证书')
        device.click_element(device.get_element_by_text('CA证书'))
        logging.info('预期结果4.进入受信任的证书')
        device.refresh_layout()
        device.assert_text_exist('系统')
        device.assert_text_exist('用户')
        device.assert_type_exist('List')
        device.assert_type_exist('ListItem')

        logging.info('步骤5.点击系统，选择某一证书')
        device.click_element(device.get_element_by_text('系统'))
        device.click_element(device.get_element_by_type('ListItem'))
        logging.info('预期结果5.证书详情弹窗正常弹出')
        device.refresh_layout()
        device.assert_type_exist('Dialog')
        device.assert_text_exist('证书详情')
        device.assert_text_exist('颁发给:')
        device.assert_text_exist('常用名称:')
        device.assert_text_exist('组织:')
        device.assert_text_exist('组织单位:')
        device.assert_text_exist('序列号:')
        device.assert_text_exist('取消')
